/*
 * Albareth - an action roleplaying game.
 * Copyright (C) 2008 Jens Anuth
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 *  02110-1301, USA.
 * 
 * $Id: GlidingScroll.java 46 2008-05-15 18:09:39Z jens464 $
*/
package albareth.frontend.slick.ui;

import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.SlickException;

import albareth.frontend.Resources;
import albareth.frontend.slick.SlickFrontend;
import albareth.frontend.slick.SlickResources;

import frosch.util.glider.Easing;

public abstract class GlidingScroll extends GlidingUIElement
{
    public static final int FROM_TOP    = 0;
    public static final int FROM_LEFT   = 1;
    public static final int FROM_RIGHT  = 2;
    public static final int FROM_BOTTOM = 3;
    
    protected SlickFrontend _frontend;

    public GlidingScroll(int start, SlickFrontend frontend)
    {
        super(80, 165, calculateStartX(start), calculateStartY(start), Easing.EASING_CUBIC, 900);
        
        _frontend = frontend;
        
        setDarkenBackground(true);
        setSize(SlickResources.SCROLL.getWidth()*2, SlickResources.SCROLL.getHeight()*2);
        
        _frontend.playSound(Resources.SOUND_ROLL_IN);
    }

    private static int calculateStartX(int start)
    {
        int startX = 0;
        switch (start)
        {
            case FROM_TOP:
                startX = 80;
                break;
            case FROM_BOTTOM:
                startX = 80;
                break;
            case FROM_RIGHT:
                startX = SlickFrontend.SCREEN_WIDTH + 640;
                break;
            default:
                startX = -640;
        }
        return startX;
    }
    //-640, 165
    private static int calculateStartY(int start)
    {
        int startY = 0;
        switch (start)
        {
            case FROM_TOP:
                startY = -292;
                break;
            case FROM_BOTTOM:
                startY = SlickFrontend.SCREEN_HEIGHT + 292;
                break;
            case FROM_RIGHT:
                startY = 165;
                break;
            default:
                startY = 164;
        }
        return startY;
    }

    public void render(Graphics g, GameContainer container, int screenX,
            int screenY) throws SlickException
    {
        SlickResources.SCROLL.draw(screenX, screenY, 2.0f);
    }

}
